﻿using System;

namespace Ecobee.Net
{
	/// <summary>
	/// Represents Ecobee API errors that occur during application execution.
	/// </summary>
	public class ErrorCodeException : EcobeeException
	{
		/// <summary>
		/// Initializes a new instance of the Ecobee.Net.ErrorCodeException class.
		/// </summary>
		public ErrorCodeException()
			: base()
		{
		}

		/// <summary>
		/// Initializes a new instance of the System.Exception class with a specified
		/// error message.
		/// </summary>
		/// <param name="message">The error message that explains the reason for the exception.</param>
		public ErrorCodeException(string message)
			: base(message)
		{
		}

		/// <summary>
		/// Initializes a new instance of the Ecobee.Net.ErrorCodeException class with a specified
		/// error message and a reference to the inner exception that is the cause of
		/// this exception.
		/// </summary>
		/// <param name="innerException">The exception that is the cause of the current exception, 
		/// or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param>
		/// <param name="message">The error message that explains the reason for the exception.</param>
		public ErrorCodeException(Exception innerException, string message)
			: base(message, innerException)
		{
		}

		/// <summary>
		/// Initializes a new instance of the System.Exception class with a specified
		/// error message. Replaces the format item in a specified string with the 
		/// string representation of a corresponding object in a specified array.
		/// </summary>
		/// <param name="format">A composite format string</param>
		/// <param name="args">An object array that contains zero or more objects to format.</param>
		public ErrorCodeException(string format, params object[] args)
			: base(string.Format(format, args))
		{
		}

		/// <summary>
		/// Initializes a new instance of the Ecobee.Net.ErrorCodeException class with a specified
		/// error message and a reference to the inner exception that is the cause of
		/// this exception. Replaces the format item in a specified string with the string 
		/// representation of a corresponding object in a specified array.
		/// </summary>
		/// <param name="innerException">The exception that is the cause of the current exception, or 
		/// a null reference (Nothing in Visual Basic) if no inner exception is specified.</param>
		/// <param name="format">A composite format string</param>
		/// <param name="args">An object array that contains zero or more objects to format.</param>
		public ErrorCodeException(Exception innerException, string format, params object[] args)
			: base(string.Format(format, args), innerException)
		{
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public static ErrorCodeException CreateErrorCodeException(Error error)
		{
			ErrorCodeException returnValue = null;

			if (error != null)
			{
				returnValue = new ErrorCodeException(error.ErrorDescription);
			}

			return returnValue;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public static ErrorCodeException CreateErrorCodeException(Status status)
		{
			ErrorCodeException returnValue = null;

			if (status != null)
			{
				returnValue = new ErrorCodeException(status.Message);
			}

			return returnValue;
		}
	}
}
